<?php


namespace app\api\library\index\novicesGoods;


use app\api\model\MallGoods;

class V
{
    public static function run($param)
    {
        $limit  = $param[ 'limit' ];
        $page   = $param[ 'page' ];
        $offset = ($page - 1) * $limit;
        //查询有无openid
        $total = MallGoods::with('spec')
            ->where([['is_novices_exclusive', '=', 1], ['status', '=', 1]])
            ->count();
        $goods = MallGoods::with([
            'spec' => function ($query) {
                $query->where('delete_time', '=', null);
            },
        ])
            ->where([['is_novices_exclusive', '=', 1], ['status', '=', 1]])
            ->order(['sort' => 'desc', 'id' => 'desc'])
            ->field('id,title,logo,market_price,discount_price,novice_price,virtual_sales')
            ->limit($offset, $limit)
            ->select()->toArray();
        foreach ($goods as $key => $value) {
            $goods[ $key ][ 'market_price' ]   = getPrice($value[ 'market_price' ]);
            $goods[ $key ][ 'discount_price' ] = getPrice($value[ 'discount_price' ]);
            $goods[ $key ][ 'novice_price' ]   = getPrice($value[ 'novice_price' ]);
        }
        $page = [
            'total'      => $total,
            'limit'      => $limit,
            'page'       => $page,
            'total_page' => ceil($total / $limit),
        ];
        $res  = [
            'page' => $page,
            'list' => $goods,
        ];
        _outPut(200, $res);
    }
}